<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>对象</title>
</head>
<body>
    <script>
        let obj = {
            name: "张三",
            age: 20
        }
        // console.log(obj.name,obj.age);
        // console.log(obj["name"],obj["age"]);

        // let a = "name";
        // console.log(obj[a],obj["a" + "g" + "e"]);

        // // delete obj.age;
        // // console.log(obj.age);

        // obj.show = function(){
        //     console.log("你好，我叫" + this.name);
        // }
        // obj.show();

        // let name = "张老师";
        let teacher = {
            name : "张老师",
            age: 30,
            gender: "女",
            talk(){
               console.log("我是" + this.name) 
            }
        }
        // console.log(teacher.name)
        // teacher.talk();

        // let students = [
        //     {
        //         name:"张飞",
        //         age:20,
        //         cls:{
        //             name:"J195",
        //             count:5
        //         }
        //     },
        //     {
        //         name:"关羽",
        //         age:21
        //     },
        //     {
        //         name:"刘备",
        //         age:22
        //     }
        // ]
        // for(let i = 0;i < students.length;i++){
        //     console.log(students[i].name,students[i].age)
        // }

        // // 遍历对象
        // for(attr in obj){
        //     console.log(attr,obj[attr]);
        // }

        // let attrs = Object.keys(obj);
        // for(attr of attrs){
        //     console.log(attr,obj[attr]);
        // }
        // console.log(Object.keys(obj).length);

        let {name:teacherName,age,gender="男"} = teacher;
        console.log(teacherName,age,gender);

    </script>
</body>
</html>